<?php
if ( !defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );
echo $header;
?>
<!-- main -->
<div class="main admin">
    <?php if(isset($message) && $message){ ?>
        <?php echo $message; ?>
    <?php }else{ ?>
    <div class="list">
        <ul>
            <?php if(empty($linkData)){ ?>
            <?php }else{ ?>
                <?php foreach($linkData as $single){ ?>
                <li>
                    <a href="<?php my_url('admin', 'link', $single['id']); ?>" class="link_title"><?php echo $single['name']; ?></a> <b><?php echo ($single['visible']) ? '可见' : '不可见'; ?></b>
                    <p>
                        <a href="<?php echo $single['url']; ?>" target="_blank"><?php echo $single['url']; ?></a>
                        <a href="<?php my_url( 'admin', 'linkdelete', $single['id'] ) ?>" onclick="return window.confirm('您确定要删除此链接么?');">删除</a>
                    </p>
                </li>
                <?php } ?>
            <?php } ?>
        </ul>
    </div>
    <div class="form">
        <?php echo isset( $extraTip ) ? $extraTip : ''; ?>
        <?php echo validation_errors(); ?>
        <?php if(isset($selectedLinkData) && $selectedLinkData ){ ?>
            <h3>修改<?php echo $selectedLinkData['name']; ?></h3>
            <?php echo form_open( base_url( 'admin/linkedit' ), '', array('id' => $selectedLinkData['id']) ); ?>
            <ul class="common_form">
                <li>
                    <p><label for="name">链接名称</label></p>
                    <?php echo form_input( array( 'id' => 'name', 'name' => 'name', 'class' => 'txtbox' ), $selectedLinkData['name'] ); ?>
                </li>
                <li>
                    <p><label for="url">网址(不需要加http)</label></p>
                    <?php echo form_input( array( 'id' => 'url', 'name' => 'url', 'class' => 'txtbox' ), $selectedLinkData['url'] ); ?>
                </li>
                <li>
                    <?php echo form_radio( 'visible', 1, ($selectedLinkData['visible'] == 1) ); ?> 可见
                    <?php echo form_radio( 'visible', 0, ($selectedLinkData['visible'] == 0) ); ?> 不可见
                </li>
                <li>
                    <?php echo form_submit( array( 'id' => 'submit', 'name' => 'submit'), '修改' ); ?>
                </li>
            </ul>
            <?php echo create_token(); ?>
            <?php echo form_close(); ?>
        <?php } else { ?>
            <h3>添加新区域</h3>
            <?php echo form_open( base_url( 'admin/linkadd' ) ); ?>
            <ul class="common_form">
                <li>
                    <p><label for="name">链接名称</label></p>
                    <?php echo form_input( array( 'id' => 'name', 'name' => 'name', 'class' => 'txtbox' ) ); ?>
                </li>
                <li>
                    <p><label for="url">网址(不需要加http)</label></p>
                    <?php echo form_input( array( 'id' => 'url', 'name' => 'url', 'class' => 'txtbox' ) ); ?>
                </li>
                <li>
                    <?php echo form_radio( 'visible', 1, true ); ?> 可见
                    <?php echo form_radio( 'visible', 0 ); ?> 不可见
                </li>
                <li>
                    <?php echo form_submit( array( 'id' => 'submit', 'name' => 'submit'), '添加' ); ?>
                </li>
            </ul>
            <?php echo create_token(); ?>
            <?php echo form_close(); ?>
        <?php } ?>
    </div>
    <div class="c"></div>
    <?php } ?>
</div>
<!-- main -->
<?php echo $footer; ?>